// e.d(r, { h: () => o });
import Lock from "./Lock"

class TypedWorker {
  worker: any
  lock: Lock
  constructor(worker) {
    this.worker = worker
    this.lock = new Lock()
  }
  async exec(t, r) {
    const e = await this.lock.lock()
    return new Promise((resolve, reject) => {
      const i = t => {
        this.worker.removeEventListener("message", i)
        resolve(t.data)
        e.unlock()
      }
      this.worker.addEventListener("message", i),
        (this.worker.onerror = t => {
          reject(t)
          e.unlock()
        })
      this.worker.postMessage(t, r)
    })
  }
}
function createWork(worker) {
  return function () {
    return new TypedWorker(new worker())
  }
}
export default { createWork }
